﻿<UserControl x:Class="Samba.Modules.SettingsModule.PrintJobView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ListViewLM="clr-namespace:Samba.Presentation.Common.ListViewLM;assembly=Samba.Presentation.Common"
     d:DesignWidth="600" mc:Ignorable="d">
    <UserControl.Resources>
        <Style TargetType="{x:Type TextBlock}" x:Key="GridBlockStyle">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Visibility" Value="{Binding Path=IsSelected,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Converter={StaticResource VisibilityConverter}, ConverterParameter=False}" />
        </Style>
        <Style TargetType="{x:Type FrameworkElement}" x:Key="GridEditStyle">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Visibility" Value="{Binding Path=IsSelected,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Converter={StaticResource VisibilityConverter}, ConverterParameter=True}" />
        </Style>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <StackPanel Grid.Row="0">
            <Label>
                <LocText ResourceIdentifierKey="PrintJobName" Suffix=":" />
            </Label>
            <TextBox HorizontalAlignment="Left" Width="250" Text="{Binding Name}" />
            <Label>
                <LocText ResourceIdentifierKey="ButtonHeader" Suffix=":" />
            </Label>
            <TextBox HorizontalAlignment="Left" Width="250" Text="{Binding ButtonText}" />
            <CheckBox IsChecked="{Binding LocksTicket}" Margin="0,5,0,2">
                <LocText ResourceIdentifierKey="LockTicket" />
            </CheckBox>
            <CheckBox IsChecked="{Binding CloseTicket}" Margin="0,2">
                <LocText ResourceIdentifierKey="CloseTicket" />
            </CheckBox>
            <CheckBox IsChecked="{Binding UseFromPos}" Margin="0,2">
                <LocText ResourceIdentifierKey="UseAtPosScreen" />
            </CheckBox>
            <CheckBox IsChecked="{Binding UseFromPaymentScreen}" Margin="0,2">
                <LocText ResourceIdentifierKey="UseAtPaymentScreen" />
            </CheckBox>
            <CheckBox IsChecked="{Binding UseFromTerminal}" Margin="0,2">
                <LocText ResourceIdentifierKey="UseAtTerminal" />
            </CheckBox>
            <CheckBox IsChecked="{Binding ExcludeVat}" Margin="0,2">
                <LocText ResourceIdentifierKey="AlwaysExcludeVat"/>
            </CheckBox>
            <CheckBox IsChecked="{Binding UseForPaidTickets}" Margin="0,2,0,5">
                <LocText ResourceIdentifierKey="UseAtOldTickets" />
            </CheckBox>
            <StackPanel Orientation="Horizontal">
                <Label>
                    <LocText ResourceIdentifierKey="PrintMapping" Suffix=":" />
                </Label>
                <TextBlock Margin="2,5">
                    <Hyperlink Command="{Binding AddPrinterMapCommand}">
                        <TextBlock Text="{Binding Path=AddPrinterMapCommand.Caption}" />
                    </Hyperlink>
                </TextBlock>
                <TextBlock Margin="2,5">
                    <Hyperlink Command="{Binding DeletePrinterMapCommand}">
                        <TextBlock Text="{Binding Path=DeletePrinterMapCommand.Caption}" />
                    </Hyperlink>
                </TextBlock>
            </StackPanel>
        </StackPanel>
        <StackPanel Grid.Column="1" Margin="20,0">
            <Label>
                <LocText ResourceIdentifierKey="PrintContent" />
            </Label>
            <ComboBox HorizontalAlignment="Left" MinWidth="230" SelectedItem="{Binding WhatToPrint}"
                 ItemsSource="{Binding WhatToPrintTypes}" />
            <Label>
                <LocText ResourceIdentifierKey="AutoPrintWhen" />
            </Label>
            <ComboBox HorizontalAlignment="Left" MinWidth="230" SelectedItem="{Binding WhenToPrint}"
                 ItemsSource="{Binding WhenToPrintTypes}" />
            <GroupBox Header="{LocText AutoPrintPaymentType}" Margin="0,5,0,0" HorizontalAlignment="Left"
                 MinWidth="250">
                <StackPanel Margin="3,5,3,5">
                    <CheckBox IsChecked="{Binding AutoPrintIfCash}">
                        <LocText ResourceIdentifierKey="Cash" />
                    </CheckBox>
                    <CheckBox IsChecked="{Binding AutoPrintIfCreditCard}">
                        <LocText ResourceIdentifierKey="CreditCard" />
                    </CheckBox>
                    <CheckBox IsChecked="{Binding AutoPrintIfTicket}">
                        <LocText ResourceIdentifierKey="Voucher" />
                    </CheckBox>
                </StackPanel>
            </GroupBox>
        </StackPanel>
        <ListView Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding PrinterMaps}" SelectedItem="{Binding SelectedPrinterMap}"
             HorizontalContentAlignment="Stretch" ListViewLM:ListViewLayoutManager.Enabled="True">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="{LocText Department}" ListViewLM:ProportionalColumn.Width="1">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <TextBlock Style="{StaticResource GridBlockStyle}" HorizontalAlignment="Stretch" Text="{Binding DepartmentLabel}" />
                                    <ComboBox Style="{StaticResource GridEditStyle}" HorizontalAlignment="Stretch" DisplayMemberPath="Name"
                                         SelectedItem="{Binding Department}" ItemsSource="{Binding Departments}" />
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{LocText Tag}" ListViewLM:ProportionalColumn.Width="1">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <TextBlock Style="{StaticResource GridBlockStyle}" HorizontalAlignment="Stretch" Text="{Binding TicketTagLabel}" />
                                    <ComboBox IsEditable="True" Style="{StaticResource GridEditStyle}" HorizontalAlignment="Stretch" SelectedItem="{Binding TicketTag}"
                                         ItemsSource="{Binding TicketTags}" />
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{LocText MenuItemGroup}" ListViewLM:ProportionalColumn.Width="1">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <TextBlock Style="{StaticResource GridBlockStyle}" HorizontalAlignment="Stretch" Text="{Binding MenuItemGroupCodeLabel}" />
                                    <ComboBox Style="{StaticResource GridEditStyle}" HorizontalAlignment="Stretch" SelectedItem="{Binding MenuItemGroupCode}"
                                         ItemsSource="{Binding MenuItemGroupCodes}" />
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{LocText MenuItem}" ListViewLM:ProportionalColumn.Width="1.5">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <TextBlock Style="{StaticResource GridBlockStyle}" HorizontalAlignment="Stretch" Text="{Binding MenuItemLabel}" />
                                    <ComboBox Style="{StaticResource GridEditStyle}" HorizontalAlignment="Stretch" DisplayMemberPath="Name"
                                         SelectedItem="{Binding MenuItem}" ItemsSource="{Binding MenuItems}" />
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{LocText Printer}" ListViewLM:ProportionalColumn.Width="1.5">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <TextBlock Style="{StaticResource GridBlockStyle}" HorizontalAlignment="Stretch" Text="{Binding PrinterLabel}" />
                                    <ComboBox Style="{StaticResource GridEditStyle}" HorizontalAlignment="Stretch" DisplayMemberPath="Name"
                                         SelectedItem="{Binding Printer}" ItemsSource="{Binding Printers}" />
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{LocText PrinterTemplate}" ListViewLM:ProportionalColumn.Width="1.5">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <TextBlock Style="{StaticResource GridBlockStyle}" HorizontalAlignment="Stretch" Text="{Binding PrinterTemplateLabel}" />
                                    <ComboBox Style="{StaticResource GridEditStyle}" HorizontalAlignment="Stretch" DisplayMemberPath="Name"
                                         SelectedItem="{Binding PrinterTemplate}" ItemsSource="{Binding PrinterTemplates}" />
                                </Grid>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
        <StackPanel Grid.Row="2" Grid.ColumnSpan="2">
            <TextBlock Text="{Binding PrintJobHint}" Foreground="Red"></TextBlock>
            <Button HorizontalAlignment="Left" Margin="0,5" MinWidth="80" Command="{Binding SaveCommand}"
                 Content="{Binding SaveCommand.Caption}" />
            <Label Content="{Binding Error}" Foreground="Red" />
        </StackPanel>
    </Grid>
</UserControl>